package com.colabo.j2ee.web.oaf.monitorperspective.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.colabo.j2ee.web.core.exception.ServiceException;
import com.colabo.j2ee.web.core.pkgenerator.IPKGenerator;
import com.colabo.j2ee.web.core.service.impl.DefaultServiceImpl;
import com.colabo.j2ee.web.oaf.monitorperspective.IHistoryOnlineService;
import com.colabo.j2ee.web.oaf.vo.IPHistoryOnlineVO;

/**
 * 历史在线最高人数统计实现类
 */
public class HistoryOnlineServiceImpl extends DefaultServiceImpl implements IHistoryOnlineService {
	protected final Log log = LogFactory.getLog(this.getClass());
	private IPKGenerator keyService;
	public IPKGenerator getKeyService() {
		return keyService;
	}

	public void setKeyService(IPKGenerator keyService) {
		this.keyService = keyService;
	}

	public Long getMaxOnlineCount() throws ServiceException {
		Long ret = Long.valueOf("0");
		List list = find_iBatis("common.getMaxHistoryOnlineCount", null);
		if (list == null || list.isEmpty()) {
			ret = Long.valueOf("0");
		} else {
			ret = (Long) list.get(0);
			if (ret == null) {
				ret = Long.valueOf("0");
			}
		}

		return ret;
	}

	public IPHistoryOnlineVO getMaxOnlineRec() throws ServiceException{		
		List list = find_iBatis("common.getMaxHistoryOnline", null);
		if (list != null && !list.isEmpty()) {
			return (IPHistoryOnlineVO) list.get(0);		
		}
		return null;
	}
	
	public void saveHistoryOnline(IPHistoryOnlineVO hisVO) throws ServiceException {
		if (hisVO != null) {
			if (hisVO.getHisId() == null) {
				hisVO.setHisId(keyService.getUUIDKey(hisVO));
				this.save_Hibernate_Object(hisVO);
			}
		}

	}

}
